package com.ruoyi.insurance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.insurance.domain.InsuranceContract;
import com.ruoyi.insurance.service.IInsuranceContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保险合同Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/insurance/contract")
public class InsuranceContractController extends BaseController
{
    @Autowired
    private IInsuranceContractService insuranceContractService;

    /**
     * 查询保险合同列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsuranceContract insuranceContract)
    {
        startPage();
        List<InsuranceContract> list = insuranceContractService.selectInsuranceContractList(insuranceContract);
        return getDataTable(list);
    }

    /**
     * 导出保险合同列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:contract:export')")
    @Log(title = "保险合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsuranceContract insuranceContract)
    {
        List<InsuranceContract> list = insuranceContractService.selectInsuranceContractList(insuranceContract);
        ExcelUtil<InsuranceContract> util = new ExcelUtil<InsuranceContract>(InsuranceContract.class);
        util.exportExcel(response, list, "保险合同数据");
    }

    /**
     * 获取保险合同详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(insuranceContractService.selectInsuranceContractById(id));
    }

    /**
     * 新增保险合同
     */
    @PreAuthorize("@ss.hasPermi('insurance:contract:add')")
    @Log(title = "保险合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsuranceContract insuranceContract)
    {
        return toAjax(insuranceContractService.insertInsuranceContract(insuranceContract));
    }

    /**
     * 修改保险合同
     */
    @PreAuthorize("@ss.hasPermi('insurance:contract:edit')")
    @Log(title = "保险合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsuranceContract insuranceContract)
    {
        return toAjax(insuranceContractService.updateInsuranceContract(insuranceContract));
    }

    /**
     * 删除保险合同
     */
    @PreAuthorize("@ss.hasPermi('insurance:contract:remove')")
    @Log(title = "保险合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(insuranceContractService.deleteInsuranceContractByIds(ids));
    }
}
